﻿using System;
using System.Collections.Generic;
using System.Linq;

namespace FiveMonth.FormWork.Word
{
    public class BookmarkInfos<T>
    {
        private List<BookmarkInfo<T>> _infos = new List<BookmarkInfo<T>>();

        public bool Any()
        {
            return _infos.Any();
        }

        public Dictionary<string, BookmarkInfo<T>> ToDictionary()
        {
            return _infos.ToDictionary(x => x.Name);
        }

        public bool Add(string name, Func<T, IList<int>, string> valueFunc)
        {
            if (_infos.Any(x => x.Name == name))
            {
                return false;
            }
            _infos.Add(new BookmarkInfo<T>(name, valueFunc));
            return true;
        }
        public bool AddImage(string name, Func<T, IList<int>, string> valueFunc, int width, int height)
        {
            if (_infos.Any(x => x.Name == name))
            {
                return false;
            }
            _infos.Add(new BookmarkInfo<T>(name, valueFunc) { Type = BookmarkType.Image, Width = width, Height = height });
            return true;
        }
        public bool AddLoop(string name, Func<T, IList<int>, int> loopCountFunc)
        {
            if (_infos.Any(x => x.Name == name))
            {
                return false;
            }
            _infos.Add(new BookmarkInfo<T>(name, loopCountFunc));
            return true;
        }
    }
}